package cn.nfwx.tv.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import cn.nfwx.tv.R;
import cn.nfwx.tv.activity.AdvertiseActivity;
import cn.nfwx.tv.base.BaseDialogFragment;
import cn.nfwx.tv.model.Movement;
import cn.nfwx.tv.util.GlideUtil;

public class MovementFragment extends BaseDialogFragment {

    Button mentCancel, mentSure;

    /**
     * 是否填满整个屏幕
     */
    protected boolean isMatchParent() {
        return true;
    }

    protected boolean isOutsideTouchable() {
        return true;
    }

    //是否透明背景
    protected boolean isTranslucentBackground() {
        return true;
    }

    protected boolean isTranslucentStatus() {
        return false;
    }

    public static MovementFragment newInstance(Movement movement) {
        MovementFragment movementFragment = new MovementFragment();
        Bundle bundle = new Bundle();
        bundle.putParcelable("movement", movement);
        movementFragment.setArguments(bundle);
        return movementFragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_network;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        final Movement movement = bundle.getParcelable("movement");
        if (movement == null) {
            dismiss();
            return;
        }
        findView(R.id.ll_network).setVisibility(View.VISIBLE);
        findView(R.id.tv_network_title).setVisibility(View.GONE);
        findView(R.id.tv_miui_network_note).setVisibility(View.GONE);
        ImageView iv_network = findView(R.id.iv_network);
        if (!TextUtils.isEmpty(movement.getImage_url())) {
            GlideUtil.loadImage(getContext(), movement.getImage_url(), iv_network);
        }
        mentCancel = findView(R.id.network_sure);
        mentCancel.setText("下次吧");
        mentCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismissAllowingStateLoss();
            }
        });
        mentSure = findView(R.id.network_free_wifi);
        mentSure.setText("去看看");
        mentSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AdvertiseActivity.startActivity(getContext(), movement.getUrl());
                dismissAllowingStateLoss();
            }
        });
    }
}
